//
//  SNEmptyView.m
//  ZhuoxinAgriculture
//
//  Created by stone on 16/12/16.
//  Copyright © 2016年 stone. All rights reserved.
//

#import "SNEmptyView.h"
#import "Masonry.h"
@interface SNEmptyView()
/** imageView */
@property (weak, nonatomic) UIImageView * iconImageView;
/** titleLabel */
@property (weak, nonatomic) UILabel * titleLabel;
@end
@implementation SNEmptyView
-(void)setImageName:(NSString *)imageName{
    _imageName = imageName;
    
    self.iconImageView.image = [UIImage imageNamed:imageName];
    
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = HexRGB(0xf5f5f5);
        [self addViews];
        [self setupUI];
        
    }
    return self;
}

- (void)addViews
{
    
    
    UIImageView * iconImageView = ({
        UIImageView * imageView = [[UIImageView alloc] init];
        //        imageView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:1.0];
        UIImage * image = [UIImage imageNamed:@"农资"];
        imageView.image = image;
        
        [self addSubview:imageView];
        
        imageView;
    });
    self.iconImageView = iconImageView;
    
    
    UILabel * titleLabel = ({
        UILabel * label = [[UILabel alloc] init];
        /** GPU 优化 */
        //        label.opaque = YES;
        //        label.backgroundColor = [UIColor whiteColor];
        //        label.layer.masksToBounds = YES;
        //------------------------------
        label.numberOfLines = 0;
        label.textColor = HexRGB(0xAFAFAF);
        label.textAlignment = NSTextAlignmentCenter;
        label.text = @"暂无数据";
        label.font = [UIFont systemFontOfSize:16];
        
        [self addSubview:label];
        
        
        
        label;
    });
    self.titleLabel = titleLabel;
}
- (void)setupUI
{
    CGFloat w = self.iconImageView.image.size.width;
    CGFloat h = self.iconImageView.image.size.height;
    CGFloat top = 367/1334.0 * [UIScreen mainScreen].bounds.size.height;
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker * make) {
        make.centerX.mas_equalTo(self.mas_centerX).offset(0);
        make.top.mas_equalTo(self.mas_top).offset(top);
        
        make.width.mas_equalTo(w);
        make.height.mas_equalTo(h);
        
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker * make) {
        make.centerX.mas_equalTo(self.mas_centerX).offset(0);
        make.top.mas_equalTo(self.iconImageView.mas_bottom).offset(18);
    }];
}

@end
